package com.lbs.droiddoctor;

import com.lbs.droiddoctor.common.HttpASync;
import com.lbs.droiddoctor.common.HttpASync.OnRequest;
import com.lbs.droiddoctor.constants.AppConstants;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class RegisterActivity extends Activity implements OnClickListener,OnRequest{
	private Button cancel;
	private EditText name;
	private EditText password;
	private EditText confirm_password;
	private EditText email;
	private EditText phonenumber;
	private Button register;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.register);
		cancel=(Button)findViewById(R.id.cancel);
        name=(EditText)findViewById(R.id.username);
        password=(EditText)findViewById(R.id.password);
        confirm_password=(EditText)findViewById(R.id.confirm_password);
        phonenumber=(EditText)findViewById(R.id.phonenumber);
        register=(Button)findViewById(R.id.register);
        email = (EditText) findViewById(R.id.email);
        cancel.setOnClickListener(this);
        register.setOnClickListener(this);
        
	}
	
	@Override
	public void onClick(View v) {
	if(v.getId()==R.id.register){
		String uname=name.getText().toString();
		String pwd1=password.getText().toString();
		String pwd2=confirm_password.getText().toString();
		String ph=phonenumber.getText().toString();
		String em=email.getText().toString();
		if(uname.equals("")||pwd2.equals("")||pwd1.equals("")||ph.equals("")||em.equals("")){
			Toast.makeText(this,"Please complete the data", Toast.LENGTH_SHORT).show();
		}
		else {
			if(pwd1.equals(pwd2))
			{
			Toast.makeText(this,"Register Success ", Toast.LENGTH_SHORT).show();
			String registerUrl = AppConstants.REGISTER_PATH+"?Email="+em+"&Name="+uname+"&Password="+pwd1+"&Phone="+ph;
			HttpASync request  = new HttpASync();
			request.setOnRequestListener(this);
			request.execute(registerUrl);
			}
			else
			Toast.makeText(this,"Password mismatch", Toast.LENGTH_SHORT).show();
		}
			
	}else if(v.getId()==R.id.cancel){
		finish();
	}
		
	}

	@Override
	public void onResponseReceived(String response) {
		// TODO Auto-generated method stub
		
	}
    
}

